<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>咨询管理</title>
<link type="text/css" rel="stylesheet" href="css/styleA.css" />
<link type="text/css" rel="stylesheet" href="css/consultA.css" />
<script type="text/javascript" src="js/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="js/jquery.md5A.js"></script>
<script type="text/javascript" src="js/jquery.jsonpA.js"></script>

<script type="text/javascript" src="js/jquery.cookieA.js"></script>
<script type="text/javascript" src="js/pupil-ajaxA.js"></script>
<script type="text/javascript" src="js/bA.js"></script>
<script type="text/javascript" src="js/styleA.js"></script>
</head>

<body>
	<div class="public-top min-cen">
    	<div class="center logo"></div>
        <a href="#">注销</a>
    </div>
    <div class="content center public">
   		<div class="menu">
        	<a class="menu-li" href="javascript:;">
            	<span class="menu-title">个人信息</span>
                <span class="menu-min-title">Personal Information</span>
            </a>
            <a class="menu-li active" href="javascript:;">
            	<span class="menu-title">咨询管理</span>
                <span class="menu-min-title">Consulting Management</span>
            </a>
            <a class="menu-li" href="javascript:;">
            	<span class="menu-title">预约管理</span>
                <span class="menu-min-title">Booking Management</span>
            </a>
            <a class="menu-li" href="javascript:;">
            	<span class="menu-title">收入记录</span>
                <span class="menu-min-title">Income Record</span>
            </a>
            <a class="menu-li" href="javascript:;">
            	<span class="menu-title">提现记录</span>
                <span class="menu-min-title">Present Record</span>
            </a>
        </div>
        <div class="puclic-right">
        	<div class="center-top" >
            	<a class="active" href="javascript:;">
                	<span class="title">未接单<b>()</b></span>
                	<span class="min-title">No Single</span>
                </a>
                <a href="javascript:;">
                	<span class="title">新咨询<b>()</b></span>
                	<span class="min-title">New Consultation</span>
                </a>
                <a href="javascript:;">
                	<span class="title">已回复未结束<b>()</b></span>
                	<span class="min-title">Has Not Ended The Reply</span>
                </a>
                <a href="javascript:;">
                	<span class="title">已回复已结束<b>()</b></span>
                	<span class="min-title">The Reply Is Over</span>
                </a>
            </div>
			<!-- 未接单 -->
        	<div class="center-frame" id="consult_0">
               	<div class="consult-frame">
               		<!--<div class="consult-li">-->
                    	<!--<span>用户名</span>-->
                        <!--<input type="text" name="unTakenName" id="unTakenName"  value="" />-->
                    <!--</div>	-->
                    <div class="consult-li">
                        <span>问题描述：</span>
                        <input type="text" name="unTakenPhone" id="unTakenPhone" value="" />
                    </div>	
                    <a class="consult-but-search"  id="unTakenConsultSearch">查询</a>
               	</div>
                <div class="consult-list">
                	<div class="consult-list-head">
                    	<span class="username">用户名</span>
                        <span class="relationship">关系</span>
                        <span class="sex">性别/年龄</span>
                        <span class="describe">问题描述</span>
                        <span class="time">生成时间</span>
                        <span class="operation">操作</span>
                    </div>
                    <div class="consult-list-body" id="unTakenConsultList">
                    </div>
                    <div class="page">
                    	<div class="page-right">
                        	<a  id="unTakenConsultPre"  style="display:none">上一页</a>
                            <a  id="unTakenConsultNext" class="active" value="2">下一页</a> 
                        </div>
                    </div>
                </div>
            </div>
			<!-- 新咨询 -->
			<div class="center-frame" id="consult_1" style="display:none;">
               	<div class="consult-frame">
                    <div class="consult-li">
                        <span>问题描述：</span>
                        <input type="text" name="unHandlePhone" id="unHandlePhone" value="" />
                    </div>	
                    <a class="consult-but-search" id="unHandleConsultSearch" >查询</a> 
               	</div>
                <div class="consult-list">
                	<div class="consult-list-head">
                    	<span class="username">用户名</span>
                        <span class="relationship">关系</span>
                        <span class="sex">性别/年龄</span>
                        <span class="describe">问题描述</span>
                        <span class="time">生成时间</span>
                        <span class="operation">操作</span>
                    </div>
                    <div class="consult-list-body consult-new" id="unHandleConsultList"> 
                    </div>
                    <div class="page">
                    	<div class="page-right">
                        	<a  id="unHandleConsultPre" style="display:none">上一页</a>
                            <a  id="unHandleConsultNext"   class="active" value="2">下一页</a> 
                        </div>
                    </div>
                </div>
            </div> 
			<!-- 已回复未结束 -->
			<div class="center-frame" id="consult_2" style="display:none;">
               	<div class="consult-frame">
                    <div class="consult-li">
                    	<span>问题描述：</span>
                        <input type="text" name="handledUnFinishedPhone" id="handledUnFinishedPhone"  value="" />
                    </div>	
                    <a class="consult-but-search"  id="handledUnFinishedSearch">查询</a> 
               	</div>
                <div class="consult-list consult-succ">
                	<div class="consult-list-head">
                    	<span class="username">用户名</span>
                        <span class="relationship">关系</span>
                        <span class="sex">性别/年龄</span>
                        <span class="describe">问题描述</span>
                        <span class="time">生成时间</span>
                        <span class="count">回复数</span>
                        <span class="operation">操作</span>
                    </div>
                    <div class="consult-list-body consult-new" id="handledUnFinishedList"> 
                    </div>
                    <div class="page">
                    	<div class="page-right">
                        	<a  id="handledUnFinishedPre" style="display:none">上一页</a>
                            <a  id="handledUnFinishedNext"  class="active" value="2">下一页</a> 
                        </div>
                    </div>
                </div>
            </div>
        	<!-- 已回复已结束 -->
			<div class="center-frame" id="consult_3" style="display:none;">
               	<div class="consult-frame">
                    <div class="consult-li">
                        <span>问题描述：</span>
                        <input type="text" name="finishConsultPhone" id="finishConsultPhone" value="" />
                    </div>	
                    <a class="consult-but-search"  id="finishConsultSearch">查询</a> 
               	</div>
                <div class="consult-list consult-succ">
                	<div class="consult-list-head">
                    	<span class="username">用户名</span>
                        <span class="relationship">关系</span>
                        <span class="sex">性别/年龄</span>
                        <span class="describe">问题描述</span>
                        <span class="time">生成时间</span>
                        <span class="count">回复数</span>
                        <span class="operation">操作</span>
                    </div>
                    <div class="consult-list-body" id="finishConsultList"> 
                    </div>
                    <div class="page">
                    	<div class="page-right">
                        	<a  id="finishConsultListPre" style="display:none">上一页</a>
                            <a  id="finishConsultListNext"   class="active" value="2">下一页</a> 
                        </div>
                    </div>
                </div>
            </div>
        
		</div>
    </div>

    <input type="hidden" id="consultId">
    <div class="alertBox">
        <div class="msgBox">
            <h3 class="date">2016年6月12日08:12:30</h3>
            <p>
                我特意QQ空间开了黄钻，就是为了在他来我空间时可以提醒，可以查看他看了我什么说说，可以在逛他空间时不让他知道，我这样是不是很喜欢他…却又不敢让他知道？我不知道他到底对我是什么想法，但是他喜欢看我每一条原创的说说和有关我择偶标准的说说
            </p>
            <button class="closeBox">收回</button>
        </div>
    </div>
	<script>
        function setCount(text,length){
            if(text.length>length){
                text=text.slice(0,length);
            }
            text+="...";
            return text;
        }
//        接单按钮
        $("#unTakenConsultList").delegate(".operation","click",function(event){
            event.preventDefault();
            ajaxPostJson(requestUrl + "/TakeConsultServlet4M", function(data, status){
                eval("rt=" + data);
                if (rt.error!="") {
                    alert(rt.error);
                }else{
                   window.location.reload();
                }
            }, {"from":"expert","expertId":$.cookie("expertId"),'consultId':$(this).attr('consultid'),"debug":1})
        })
		$(function(){
            getUnTakenConsult(1,null,null);
            getCount($.cookie("expertId"));
			$(".center-top >a").click(function(){
				var i = $(this).index();
                var text=$(this).find(".title").html().slice(0,3);
                if(text==="未接单"){
                    getUnTakenConsult(1,null,null);
                }else  if(text==="新咨询"){
                    getUnHandleConsult(1,null,null);
                }else  if(text==="已回复"){
                    if($(this).find(".title").html().slice(3,6)==="未结束"){
                        getHandledUnFinished(1,null,null);
                    }else{
                        getFinishConsult(1,null,null);
                    }
                }
				$(".center-top >a").removeClass("active"); 
				$(".center-frame").css("display","none");
				$(this).addClass("active");
				$("#consult_"+i).css("display","block");
				}
			); 
			//查询按钮
			$("#unTakenConsultSearch").click(function(){
				var problem = $("#unTakenPhone").val();
				getUnTakenConsult(1,problem);
			});
			$("#unHandleConsultSearch").click(function(){
				var problem = $("#unHandlePhone").val();
				getUnHandleConsult(1,problem);
			});
			$("#handledUnFinishedSearch").click(function(){
				var problem = $("#handledUnFinishedPhone").val();
				getHandledUnFinished(1,problem);
			});
			$("#finishConsultSearch").click(function(){
				var problem = $("#finishConsultPhone").val();
				getFinishConsult(1,problem);
			});
			//上一页下一页按钮
			//获取未处理订单
			$("#unTakenConsultPre").click(function(){
				var page = $(this).attr("value");
				if(page==1){
					$(this).css("display","none");
				}
				$(this).attr("value",parseInt(page)-1);
				getUnTakenConsult(page,null,null);
			});
			$("#unTakenConsultNext").click(function(){
				var page = $(this).attr("value");
				if(page==2){
					$(this).css("display","block");
				}
				$(this).attr("value",parseInt(page)+1);  
				getUnTakenConsult(page,null,null);
			});
			//获取新咨询
			$("#unHandleConsultPre").click(function(){
				var page = $(this).attr("value");
				if(page==2){
					$(this).css("display","block");
				}
				$(this).attr("value",parseInt(page)-1);
				getUnHandleConsult(page,null,null);
			});
			$("#unHandleConsultNext").click(function(){
				var page = $(this).attr("value");
				if(page==2){
					$(this).css("display","block");
				}
				$(this).attr("value",parseInt(page)+1);
				getUnHandleConsult(page,null,null);
			});
			//获取已回复未结束
			$("#handledUnFinishedPre").click(function(){
				var page = $(this).attr("value");
				if(page==2){
					$(this).css("display","block");
				}
				$(this).attr("value",parseInt(page)-1);
				getHandledUnFinished(page,null,null);
			});
			$("#handledUnFinishedNext").click(function(){
				var page = $(this).attr("value");
				if(page==2){
					$(this).css("display","block");
				}
				$(this).attr("value",parseInt(page)+1);
				getHandledUnFinished(page,null,null);
			});
			//获取已结束咨询
			$("#finishConsultListPre").click(function(){
				var page = $(this).attr("value");
				if(page==2){
					$(this).css("display","block");
				}
				$(this).attr("value",parseInt(page)-1);
				getFinishConsult(page,null,null);
			});
			$("#finishConsultListNext").click(function(){
				var page = $(this).attr("value");
				if(page==2){
					$(this).css("display","block");
				}
				$(this).attr("value",parseInt(page)+1);
				getFinishConsult(page,null,null);
			});
            /*******结束按钮******/
            $(".consult-list").delegate(".operation","click",function(event){
                event.stopPropagation();
                var consultId=$(this).attr("consultid");
                if($(this).html()==="结束"){
                    var me=this;
                    ajaxPostJson(requestUrl + "/FinishConsultServlet4M", function(data, status){
                        eval("rt=" + data);
                        if(rt.error!==""){
                            alert(rt.error);
                        }else{
                            $(me).parent().remove();
                        }
                    }, {"from":"expert","consultId":consultId,"debug":1,"expertId":1});
                }else if($(this).html()==="操作"){
                    ajaxPostJson(requestUrl + "/TakeConsultServlet4M", function(data, status){
                        eval("rt=" + data);
                        if(rt.error!==""){
                            alert(rt.error);
                        }
                    }, {"from":"expert","consultId":consultId,"debug":1,"expertId":1});
                }else if($(this).html()==="回复"){
                    window.location.href='consult_detailA.html?consultId='+$(this).attr('consultid');
                }else if($(this).html()==="详情"){
                    window.location.href='consult_detailA.html?consultId='+$(this).attr('consultid');
                }
            });
            $(".consult-list").delegate(".describe>a","click",function(event){
                var consultId=$(this).attr("consultId");
                $(".alertBox>.msgBox>.date").html($(this).parent().siblings('.time').html());
                $(".alertBox>.msgBox>p").html($(this).attr('data-desc'));
                $(".alertBox").fadeIn();
            })
            /********间隔5秒获取数据******/
            setInterval(function(){
                var expertId = $.cookie("expertId");
                getCount(expertId);
            },5000);
		});
        function getCount(expertId){
            ajaxPostJson(requestUrl + "/GetConsultNumServlet4M", function(data, status){
                eval("rt=" + data);
                if (rt.error!="") {
                    alert(rt.error);
                }else{
                    if(rt.consultNum1>0){
                        $('.center-top>a').eq(1).find('b').html('('+rt.consultNum1+')').show();
                    }
                    if(rt.consultNum2>0){
                        $('.center-top>a').eq(2).find('b').html('('+rt.consultNum2+')').show();
                    }
                    if(rt.consultNum3>0){
                        $('.center-top>a').eq(3).find('b').html('('+rt.consultNum3+')').show();
                    }
                    if(rt.consultNum4>0){
                        $('.center-top>a').eq(0).find('b').html('('+rt.consultNum4+')').show();
                    }
                }
            }, {"from":"expert","expertId":expertId,"debug":1});

        }
		//获取未处理订单
		function getUnTakenConsult(page,desc){
			var expertId = $.cookie("expertId");
			ajaxPostJson(requestUrl + "/ReturnUnTakenConsultServlet4M", function(data, status){
				eval("rt=" + data);
				if (rt.error!="") {
					$("#unTakenConsultNext").css("display","none");
					alert(rt.error);
				}else{ 
					var consultList =  rt.consultList; 
					var htmlStr ="";
					if(typeof(consultList)!="undefined"){
						$.each(consultList,function(consult){
						    var list=consultList[consult];
						htmlStr+= "<div class=\"consult-list-li\">"
                                    +"<span class=\"username\">"+list.user_nickname+"</span>"
                                    +"<span class=\"relationship\">"+list.relationship+"</span>"
                                    +"<span class=\"sex\">"+list.gender+"/"+list.age+"</span>"
                                    +"<span class=\"describe\">"+autoAddEllipsis(list.describe,44)
                                        +"<span >"+setCount(list.description,25)+"</span>"
                                         +"<a href=\"javascript:;\" describe=\""+list.describe+"\" uuid=\""+list.uuid+"\" consultId=\""+list.consultId+"\" data-desc="+list.description+">详情</a></span>"
                                    +"<span class=\"time\">"+(list.commitTime.slice(0,-2))+"</span>"
                                    +"<a class=\"operation\" href=\"#\" uuid=\""+list.uuid+"\"   consultId ="+list.consultId+">接单</a>"
								+"</div>";
						});
                    }
					$("#unTakenConsultList").html(htmlStr);
                    // 右侧高度自适应
                    $('.menu').height($('.content.public').height());
				}
			}, {"from":"expert","currentpage":page,"desc":$("#unTakenPhone").val(),"expertId":expertId,"debug":1});
		}
		//获取新咨询
		function getUnHandleConsult(page,desc){
			var expertId = $.cookie("expertId");
			ajaxPostJson(requestUrl + "/ReturnUnHandleConsultServlet4M", function(data, status){
				eval("rt=" + data);
				if (rt.error!="") {
					$("#unHandleConsultNext").css("display","none");
					alert(rt.error);
				}else{ 
					var consultList =  rt.consultList; 
					var htmlStr ="";
					if(typeof(consultList)!="undefined"){
					    for(var i=0;i<consultList.length;i++){
                            var list=consultList[i];
                            htmlStr+= "<div class=\"consult-list-li\">"
                                    +"<span class=\"username\">"+list.user_nickname+"</span>"
                                    +"<span class=\"relationship\">"+list.relationship+"</span>"
                                    +"<span class=\"sex\">"+list.gender+"/"+list.age+"</span>"
                                    +"<span class=\"describe\">"+autoAddEllipsis(list.describe,44)
                                    +"<span>"+setCount(list.description,25)+"</span>"
                                    +"<a href=\"javascript:;\" describe=\""+list.describe+"\" consultId=\""+list.consultId+"\" data-desc="+list.description+">详情</a></span>"
                                    +"<span class=\"time\">"+(list.commitTime.slice(0,-2))+"</span>"
                                    +"<a class=\"operation\"  uuid=\""+list.uuid+"\" consultId ="+list.consultId+">回复</a>"
                                    +"<a class=\"operation\"  uuid=\""+list.uuid+"\" consultId ="+list.consultId+">结束</a> "
                                    +"</div>";
                        }
					}
                    $("#unHandleConsultList").html(htmlStr);
                    // 右侧高度自适应
                    $('.menu').height($('.content.public').height());
				}
			}, {"from":"expert","currentpage":page,"desc":$("#unHandlePhone").val(),"expertId":expertId,"debug":1});
		}
		//获取已回复未结束
		function getHandledUnFinished(page,desc){
			var expertId = $.cookie("expertId");
			ajaxPostJson(requestUrl + "/ReturnHandledUnFinishedConsultServlet4M", function(data, status){
				eval("rt=" + data);
				if (rt.error!="") {
					$("#handledUnFinishedNext").css("display","none");
					alert(rt.error);
				}else{ 
					var consultList =  rt.consultList; 
					var htmlStr ="";
					if(typeof(consultList)!="undefined"){
						$.each(consultList,function(consult){
                            var list=consultList[consult];
						htmlStr+= "<div class=\"consult-list-li\">"
								+"<span class=\"username\">"+list.user_nickname+"</span>"
								+"<span class=\"relationship\">"+list.relationship+"</span>"
								+"<span class=\"sex\">"+list.gender+"/"+list.age+"</span>"
								+"<span class=\"describe\">"+autoAddEllipsis(list.describe,44)
                                +"<span>"+setCount(list.description,25)+"</span>"
								+"<a href=\"javascript:;\" describe=\""+list.describe+"\" consultId=\""+list.consultId+"\" data-desc="+list.description+">详情</a></span>"
								+"<span class=\"time\">"+list.commitTime+"</span>"
                                +"<span class='replyNum'>"+list.replyNum+"</span>"
								+"<a class=\"operation\"  uuid=\""+list.uuid+"\" consultId ="+list.consultId+">回复</a>"
								+"<a class=\"operation\"  uuid=\""+list.uuid+"\" consultId ="+list.consultId+">结束</a> "
								+"</div>";
						}); 
					}
					$("#handledUnFinishedList").html(htmlStr);
                    // 右侧高度自适应
                    $('.menu').height($('.content.public').height());
				}
			}, {"from":"expert","currentpage":page,"desc":$("#handledUnFinishedPhone").val(),"expertId":expertId,"debug":1,"consultId":getConsultId()});
		}
		//获取已结束咨询
		function getFinishConsult(page,desc){
			var expertId = $.cookie("expertId");
			ajaxPostJson(requestUrl + "/ReturnFinishedConsultServlet4M", function(data, status){
				eval("rt=" + data);
				if (rt.error!="") {
					$("#finishConsultListNext").css("display","none");
					alert(rt.error);
				}else{ 
					var consultList =  rt.consultList; 
					var htmlStr ="";
					if(typeof(consultList)!="undefined"){
						$.each(consultList,function(consult){
						    var list=consultList[consult];
						htmlStr+= "<div class=\"consult-list-li\">"
								+"<span class=\"username\">"+list.user_nickname+"</span>"
								+"<span class=\"relationship\">"+list.relationship+"</span>"
								+"<span class=\"sex\">"+list.gender+"/"+list.age+"</span>"
								+"<span class=\"describe\">"
                                +"<span>"+autoAddEllipsis(list.description,44)+"</span>"
								+"<a href=\"javascript:;\" describe=\""+list.describe+"\" consultId=\""+list.consultId+"\" data-desc="+list.description+" >详情</a></span>"
								+"<span class=\"time\">"+list.commitTime+"</span>"
								+"<span class=\"count\">"+list.replyNum+"</span>"
								+"<a class=\"operation\"  uuid=\""+list.uuid+"\" consultId ="+list.consultId+">详情</a>"
								+"</div>";
						}); 
					}
					$("#finishConsultList").html(htmlStr);
                    // 右侧高度自适应
                    $('.menu').height($('.content.public').height());
				}
			}, {"from":"expert","currentpage":page,"desc":desc,"expertId":expertId,"debug":1,"consultId":getConsultId()});
		}
		//获取consultId
        function getConsultId(){
            return 6604;
        }
	</script>
</body>
</html>
